package UIComponents// ActionScript file
{
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;

	public class UIBuilding extends Sprite
	{
		private var _decorations:DisplayObject;
		private var _storage:DisplayObject;
		private var _buildings:DisplayObject;
		private var _wallHandler:DisplayObject;
		public function UIBuilding():void
		{
			this.init();
		}
		
		private function init():void
		{
//			this._decorations=this.getChildByName("layer_decorations");
//			this._storage=this.getChildByName("layer_storage");
//			this._buildings=this.getChildByName("layer_buildings");
//			this._wallHandler=this.getChildByName("layer_wallHandler");
//			this.showDecorations();
//			this.addListener();
			(this.getChildByName("button_storage") as MyButton).lockState=true;
		}
		
		private function addListener():void
		{
			(this.getChildByName("button_decorations") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,showDecorationsHandler);
			(this.getChildByName("button_buildings") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,showBuildingsHandler);
			(this.getChildByName("button_storage") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,showStorageHandler);
			(this.getChildByName("button_wallHandler") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,showWallHandlerHandler);
			(this.getChildByName("button_sure") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,sureHandler);
			(this.getChildByName("button_return") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,returnHandler);
			(this.getChildByName("button_move") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,moveHandler);
			(this.getChildByName("button_clean") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,cleanHandler);
		}
		
		private function removeListener():void
		{
			(this.getChildByName("button_decorations") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,showDecorationsHandler);
			(this.getChildByName("button_buildings") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,showBuildingsHandler);
			(this.getChildByName("button_storage") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,showStorageHandler);
			(this.getChildByName("button_wallHandler") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,showWallHandlerHandler);
			(this.getChildByName("button_sure") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,sureHandler);
			(this.getChildByName("button_return") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,returnHandler);
			(this.getChildByName("button_move") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,moveHandler);
			(this.getChildByName("button_clean") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,cleanHandler);
		}
		
		private function showDecorationsHandler(e:ComponentEvent):void
		{
			this.showDecorations();
			(this.getChildByName("button_decorations") as MyButton)["lockState"]=true;
			(this.getChildByName("button_buildings") as MyButton)["lockState"]=false;
			(this.getChildByName("button_storage") as MyButton)["lockState"]=false;
		}
		
		private function showBuildingsHandler(e:ComponentEvent):void
		{
			this.showBuildings();
			(this.getChildByName("button_decorations") as MyButton).lockState=false;
			(this.getChildByName("button_buildings") as MyButton).lockState=true;
			(this.getChildByName("button_storage") as MyButton).lockState=false;
		}
		
		private function showStorageHandler(e:ComponentEvent):void
		{
			this.showStorage();
			(this.getChildByName("button_decorations") as MyButton).lockState=false;
			(this.getChildByName("button_buildings") as MyButton).lockState=false;
			(this.getChildByName("button_storage") as MyButton).lockState=true;
		}
		
		private function showWallHandlerHandler(e:ComponentEvent):void
		{
			this.showWallHandler();
		}
		
		private function sureHandler(e:ComponentEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.CLOSE,true));
		}
		
		private function returnHandler(e:ComponentEvent):void
		{
			
		}
		
		private function moveHandler(e:ComponentEvent):void
		{
		}
		
		private function cleanHandler(e:ComponentEvent):void
		{
			
		}
		
		public function showDecorations():void
		{
			this.hideAll();
			this.decorations.visible=true;
		}
		
		public function showStorage():void
		{
			this.hideAll();
			this.storage.visible=true;
		}
		
		public function showBuildings():void
		{
			this.hideAll();
			this.buildings.visible=true;
		}
		
		public function showWallHandler():void
		{
			this.hideAll();
			this.wallHandler.visible=true;
		}
		
		private function hideAll():void
		{
			this.decorations.visible=false;
			this.storage.visible=false;
			this.buildings.visible=false;
			this.wallHandler.visible=false;
		}
		
		public function release():void
		{
			
		}

		/*getter & setter*/
		public function get decorations():DisplayObject
		{
			return _decorations;
		}

		public function get storage():DisplayObject
		{
			return _storage;
		}

		public function get buildings():DisplayObject
		{
			return _buildings;
		}

		public function get wallHandler():DisplayObject
		{
			return _wallHandler;
		}


	}
}